<?php

namespace app\api\model;

use app\common\model\OrderGoods as OrderGoodsModel;

/**
 * 订单商品模型
 * Class OrderGoods
 * @package app\api\model
 */
class OrderGoods extends OrderGoodsModel
{
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'content',
        'wxapp_id',
        'create_time',
    ];

    /**
     * 获取未评价的商品
     * @param $order_id
     * @return OrderGoods[]|false
     * @throws \think\exception\DbException
     */
    public static function getNotCommentGoodsList($order_id)
    {
        return self::all(['order_id' => $order_id, 'is_comment' => 0], ['orderM', 'image']);
    }

    /**
     * 通过商品获取预约订单信息
     * @param $order_goods_id
     * @param $user_id
     * @return bool
     */
    public function getServiceType($order_goods_id, $user_id)
    {
        $order = $this->where('goods_id', $order_goods_id)
            ->where('user_id', $user_id)
            ->where('is_delete', 0)
            ->find();
        if (!$order) {
            $this->setError('订单不存在');
            return false;
        }
    }

    public function getOrderType($order_id)
    {
        return $this->alias('o')
            ->where('o.order_id', $order_id)
            ->join("order_goods goods", 'goods.goods_id = o.goods_id', 'left')
            ->value('goods.goods_type');
    }
}
